package com.lee.boot.head.first.demo.controller;


import com.lee.boot.head.first.demo.util.Test;
import com.lee.boot.head.first.demo.util.ThreadPoolUtils.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Auther: Lee
 * @Date: 2018/6/8 15:47
 * @Description:
 */
@RestController
public class DemoController {

    @Autowired
    private Test test;

    @Autowired
    private ThreadPoolUtil poolUtil;


    Logger logger = LoggerFactory.getLogger(DemoController.class);

    public DemoController() {
        System.out.println("new");
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        logger.error("errorerrorerrorerrorerrorerror");
        logger.debug("debugdebugdebugdebugdebugdebug");
        logger.info("infoinfoinfoinfoinfoinfoinfoinfo");
        logger.warn("debugdebugdebugdebug");
        poolUtil.goGoGo();
        return "index";
    }

    @RequestMapping(value = "/a")
    public String test() {

        for (int i = 0; i < 1000; i++) {
            int x = i;
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                test.getA();
            });
            t.start();
            if (i == 999) {
                System.out.println("aaaa" + Test.a);
            }
        }
        return String.valueOf(Test.a);
    }


}
